package com.maidada.codesharebackend.common;

import com.maidada.codesharebackend.exception.BusinessException;
import com.maidada.codesharebackend.exception.ErrorCode;

/**
 * 异常抛出工具类，可简化代码
 *
 * @author wulinxuan
 * @date 2024/12/19 17:43
 */
public class ThrowUtils {

    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    public static void throwIf(boolean condition, ErrorCode errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    public static void throwIf(boolean condition, ErrorCode errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }
}
